package com.baidu.tcpChatDemo2.thread;

public class D02_ThreadApi01 {
    public static void main(String[] args) {
        MyThread thread1 = new MyThread("1号");
        //thread1.setName("1号");
        thread1.start();
        System.out.println(thread1.getName());

        MyThread thread2 = new MyThread("2号");
        thread2.start();
        System.out.println(thread2.getName());

        System.out.println("当前执行的线程是 :" + Thread.currentThread().getName());

    }
}

class MyThread extends Thread{
    public MyThread() {
    }

    //创建有参构造器 直接将参数传递给父类  用super
    public MyThread(String name) {
        super(name);
    }

    @Override
    public void run() {
        for (int i = 0; i < 5; i++) {
            System.out.println(this.getName() + "线程: " + i);
        }
    }
}
